/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
* ComGLHoodOOptions.java
*
* Created on December 8, 2007, 11:29 AM
 */
package gui.genomemap.view.outputView.options;

import gui.genomemap.outputModel.ComJLHoodOModel;
import gui.genomemap.report.ReportGenerator;
import gui.genomemap.view.ViewManager;

import javax.swing.SwingWorker;

/**
 *
 * @author  stewari1
 */
public class ComJLHoodOOptions extends OutputOptions {


    // Variables declaration - do not modify//GEN-BEGIN:variables

    /** Field description */
    private javax.swing.JCheckBox fullMap_JCheckBox;

    /** Field description */
    private javax.swing.JCheckBox genePubMap_JCheckBox;

    /** Field description */
    private javax.swing.JCheckBox geneSeqMap_JCheckBox;

    /** Field description */
    private javax.swing.JButton jButton1;

    /** Field description */
    private javax.swing.JList jList1;

    /** Field description */
    private javax.swing.JPanel jPanel2;

    /** Field description */
    private javax.swing.JPanel jPanel3;

    /** Field description */
    private javax.swing.JPanel jPanel6;

    /** Field description */
    private javax.swing.JScrollPane jScrollPane1;

    /** Field description */
    private javax.swing.JSeparator jSeparator1;

    /** Field description */
    private javax.swing.JCheckBox probeSeqMap_JCheckBox;

    /** Field description */
    private javax.swing.JButton run_JButton;

    /** Creates new form ComGLHoodOOptions */
    public ComJLHoodOOptions(java.awt.Frame parent, boolean modal) {

        super(parent, modal);

        initComponents();
    }

    /**
     * This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */


    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3               = new javax.swing.JPanel();
        jPanel2               = new javax.swing.JPanel();
        probeSeqMap_JCheckBox = new javax.swing.JCheckBox();
        jPanel6               = new javax.swing.JPanel();
        genePubMap_JCheckBox  = new javax.swing.JCheckBox();
        geneSeqMap_JCheckBox  = new javax.swing.JCheckBox();
        fullMap_JCheckBox     = new javax.swing.JCheckBox();
        run_JButton           = new javax.swing.JButton();
        jScrollPane1          = new javax.swing.JScrollPane();
        jList1                = new javax.swing.JList();
        jSeparator1           = new javax.swing.JSeparator();
        jButton1              = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Advanced Output Options");
        jPanel3.setLayout(new java.awt.CardLayout());
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Physical Map "));
        probeSeqMap_JCheckBox.setSelected(true);
        probeSeqMap_JCheckBox.setText("Probe Sequence Map");
        probeSeqMap_JCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        probeSeqMap_JCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Integrated Genetic Map"));
        genePubMap_JCheckBox.setSelected(true);
        genePubMap_JCheckBox.setText("Published Map");
        genePubMap_JCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        genePubMap_JCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
        geneSeqMap_JCheckBox.setSelected(true);
        geneSeqMap_JCheckBox.setText("Sequence Map");
        geneSeqMap_JCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        geneSeqMap_JCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);

        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                jPanel6Layout.createSequentialGroup().addContainerGap().addGroup(
                    jPanel6Layout.createParallelGroup(
                        javax.swing.GroupLayout.Alignment.LEADING).addComponent(
                        genePubMap_JCheckBox).addComponent(geneSeqMap_JCheckBox)).addContainerGap(
                            137, Short.MAX_VALUE)));
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                jPanel6Layout.createSequentialGroup().addContainerGap().addComponent(
                    genePubMap_JCheckBox).addPreferredGap(
                    javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(
                    geneSeqMap_JCheckBox).addContainerGap(73, Short.MAX_VALUE)));
        fullMap_JCheckBox.setSelected(true);
        fullMap_JCheckBox.setText("Create Full Map");
        fullMap_JCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        fullMap_JCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);

        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                jPanel2Layout.createSequentialGroup().addContainerGap().addGroup(
                    jPanel2Layout.createParallelGroup(
                        javax.swing.GroupLayout.Alignment.LEADING).addComponent(
                        probeSeqMap_JCheckBox).addComponent(fullMap_JCheckBox).addComponent(
                        jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.PREFERRED_SIZE)).addContainerGap(
                            122, Short.MAX_VALUE)));
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                jPanel2Layout.createSequentialGroup().addComponent(
                    probeSeqMap_JCheckBox).addPreferredGap(
                    javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(
                    fullMap_JCheckBox).addPreferredGap(
                    javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(
                    jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE,
                    javax.swing.GroupLayout.DEFAULT_SIZE,
                    javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap(59, Short.MAX_VALUE)));
        jPanel3.add(jPanel2, "card2");
        run_JButton.setText("Run");
        run_JButton.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                run_JButtonActionPerformed(evt);
            }

        });
        jList1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Options Category",
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                javax.swing.border.TitledBorder.ABOVE_TOP));
        jList1.setModel(new javax.swing.AbstractListModel() {

            final String[] strings = { "Maps" };
            public int getSize() {
                return strings.length;
            }
            public Object getElementAt(int i) {
                return strings[i];
            }

        });
        jScrollPane1.setViewportView(jList1);
        jButton1.setText("Cancel");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 576, Short
                        .MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout
                                    .PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(21, 21, 21)
                                        .addComponent(jPanel3, javax.swing.GroupLayout
                                            .DEFAULT_SIZE, 398, Short.MAX_VALUE))
                                                .addGroup(javax.swing.GroupLayout.Alignment
                                                    .TRAILING, layout.createSequentialGroup()
                                                        .addComponent(run_JButton)
                                                            .addPreferredGap(javax.swing.LayoutStyle
                                                                .ComponentPlacement.RELATED)
                                                                    .addComponent(jButton1)))
                                                                        .addContainerGap()));
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                layout.createSequentialGroup().addGroup(
                    layout.createParallelGroup(
                        javax.swing.GroupLayout.Alignment.LEADING).addComponent(
                        jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 291,
                        Short.MAX_VALUE).addComponent(
                            jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 291,
                            javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(
                                33, 33, 33).addComponent(
                                jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10,
                                javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(
                                    javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
                                    layout.createParallelGroup(
                                        javax.swing.GroupLayout.Alignment.BASELINE).addComponent(
                                        run_JButton).addComponent(jButton1)).addContainerGap()));
        pack();

    }    // </editor-fold>//GEN-END:initComponents

    /**
     * Method description
     *
     * @param evt description
     */
    private void run_JButtonActionPerformed(java.awt.event.ActionEvent evt) {    // GEN-FIRST:event_run_JButtonActionPerformed


        // get the output model
        final ComJLHoodOModel outputModel = (ComJLHoodOModel) getModelTreeNode().getOutputModel();


        // get the current options
        getOptions(outputModel);


        // save the model:
        // getOutputView().getView().getManager().saveModels();
        // run viewers on the model
        SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {

            public Void doInBackground() {

                ReportGenerator viewer = new ReportGenerator(outputModel);

                try {

                    viewer.show();

                    ViewManager viewManager = getOutputView().getView().getManager();

                    viewManager.saveModels();
                    getOutputView().getView().getTree().expandModelNode(outputModel);
                    getModelTreeNode().referesh();

                } catch (Exception ex) {
                    ex.printStackTrace();
                }

                return null;
            }
        };

        worker.execute();
        this.dispose();
    }    // GEN-LAST:event_run_JButtonActionPerformed

    public void setOptions(ComJLHoodOModel outputModel) {


        // Map
        // createMap_JCheckBox.setSelected(outputModel.getOptionsModel().isCreatingMap());
        probeSeqMap_JCheckBox.setSelected(outputModel.getOptionsModel().isComparingProbeSeqMap());
        fullMap_JCheckBox.setSelected(outputModel.getOptionsModel().isCreatingFullMap());
        genePubMap_JCheckBox.setSelected(outputModel.getOptionsModel().isComparingGenePubMap());
        geneSeqMap_JCheckBox.setSelected(outputModel.getOptionsModel().isComparingGeneSeqMap());
    }

    void getOptions(ComJLHoodOModel outputModel) {


        // Map
        // outputModel.getOptionsModel().setCreatingMap(createMap_JCheckBox.isSelected());
        outputModel.getOptionsModel().setComparingProbeSeqMap(probeSeqMap_JCheckBox.isSelected());
        outputModel.getOptionsModel().setCreatingFullMap(fullMap_JCheckBox.isSelected());
        outputModel.getOptionsModel().setComparingGenePubMap(genePubMap_JCheckBox.isSelected());
        outputModel.getOptionsModel().setComparingGeneSeqMap(geneSeqMap_JCheckBox.isSelected());
    }


    // End of variables declaration//GEN-END:variables
}
